<template>
  <!-- 员工实名认证审核 -->
  <div class="check">
      {{certificationlist.id}}
    <!-- 头部日期查询 -->
    <div class="header">
      <el-date-picker
        v-model="Time"
        type="datetimerange"
        :picker-options="pickerOptions"
        range-separator="至"
        start-placeholder="开始日期"
        end-placeholder="结束日期"
        align="right"
      />
      <!-- 审核下拉选择框 -->
      <el-select v-model="Certstatus" clearable placeholder="请选择状态">
        <el-option label="通过" value="通过" />
        <el-option label="不通过" value="不通过" />
        <el-option label="未审核" value="未审核" />
      </el-select>
      <!-- 申请人编号输入框 -->
      <el-input
        v-model="userid"
        placeholder="请输入申请人编号"
        style="width: 240px"
        clearable
      />
      <!-- 查询按钮 -->
      <el-button type="success" @click="choose">查询</el-button>
    </div>
    <!-- 表格数据展示区 -->
    <div class="table_content">
      <el-table :data="certificationlist" style="width: 100%">
        <!-- 序号 -->
        <el-table-column type="index" label="序号" align="center" />
        <!-- 申请人编号 -->
        <el-table-column prop="userId" label="申请人编号" align="center" />
        <!-- 姓名 -->
        <el-table-column prop="realname" label="姓名" align="center" />
        <!-- 申请时间 -->
        <el-table-column prop="applyTime" label="申请时间" align="center">
          <template slot-scope="scope">
            <span>{{
              moment(scope.row.applyTime).format("YYYY-MM-DD HH:mm:SS")
            }}</span>
          </template>
        </el-table-column>
        <!-- 身份证号码 -->
        <el-table-column prop="idCard" label="身份证号码" align="center" />
        <!-- 身份证正面 -->
        <el-table-column label="身份证正面" align="center">
          <template slot-scope="scope">
            <el-image
              style="width: 40px; height: 40px"
              :src="scope.row.idcardPhotoPositive"
              :preview-src-list="[scope.row.idcardPhotoPositive]"
            />
          </template>
        </el-table-column>
        <!-- 身份证反面 -->
        <el-table-column label="身份证反面" align="center">
          <template slot-scope="scope">
            <el-image
              style="width: 40px; height: 40px"
              :src="scope.row.idcardPhotoNegative"
              :preview-src-list="[scope.row.idcardPhotoNegative]"
            />
          </template>
        </el-table-column>
        <!-- 银行卡卡号 -->
        <el-table-column prop="bankCard" label="银行卡卡号" align="center" />
        <!-- 银行卡 -->
        <el-table-column label="银行卡" align="center">
          <template slot-scope="scope">
            <el-image
              style="width: 40px; height: 40px"
              :src="scope.row.bankCardPhoto"
              :preview-src-list="[scope.row.bankCardPhoto]"
            />
          </template>
        </el-table-column>
        <!-- 状态 -->
        <el-table-column label="状态" show-overflow-tooltip align="center">
          <template slot-scope="scope">
            <el-tag
              v-if="scope.row.status == '通过'"
              size="small"
              type="success"
            >
              {{ scope.row.status }}
            </el-tag>
            <el-tag
              v-else-if="scope.row.status == '不通过'"
              size="small"
              type="danger"
            >
              {{ scope.row.status }}
            </el-tag>
            <el-tag
              v-else-if="scope.row.status == '未审核'"
              size="small"
              type="info"
            >
              {{ scope.row.status }}
            </el-tag>
          </template>
        </el-table-column>
        <!-- 操作 -->
        <el-table-column label="操作" align="center">
          <template slot-scope="scope">
            <span v-if="scope.row.status=='未审核'">
              <el-button type="text" size="small" style="color:#E6A23C" @click="handleClick(scope.row.id)">撤销</el-button>
              <el-button type="text" size="small" style="color:#67C23A" @click="checkpass(scope.row.id)">通过</el-button>
              <el-button type="text" size="small" style="color:#F56C6C" @click="checknopass(scope.row.id)">不通过</el-button>
            </span>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <!-- 底部分页查询 -->
    <div class="footer">
      <el-pagination
        :current-page="currentPage"
        :page-sizes="[2, 4, 6, 8]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />
    </div>
  </div>
</template>

<script>
import { get, post } from '@/utils/request'
const moment = require('moment')
export default {
  data() {
    return {
      // 日历
      pickerOptions: {
        shortcuts: [{
          text: '最近一周',
          onClick(picker) {
            const end = new Date()
            const start = new Date()
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 7)
            picker.$emit('pick', [start, end])
          }
        }, {
          text: '最近一个月',
          onClick(picker) {
            const end = new Date()
            const start = new Date()
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 30)
            picker.$emit('pick', [start, end])
          }
        }, {
          text: '最近三个月',
          onClick(picker) {
            const end = new Date()
            const start = new Date()
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 90)
            picker.$emit('pick', [start, end])
          }
        }]
      },
      value: '',
      // 页面展示数据的总条数
      total: 10,
      // 当前页码
      currentPage: 1,
      // 每页要展示的数据
      pageSize: 8,
      // 实名认证信息数组
      certificationlist: [],
      // 查询时间
      Time: [],
      // 审核状态下拉框
      Certstatus: '',
      // 申请人编号
      userid: '',
      // 查询审核信息对象
      queryData: {}
    }
  },

  computed: {},
  created() {
    this.getAllcertification()
  },
  mounted() {},
  methods: {
    // 时间函数
    moment,
    // 拿到全部实名认证信息
    async getAllcertification() {
      const data = {
        page: this.currentPage,
        pageSize: this.pageSize
      }
      const res = await get('/certification/pageQueryCertificationApply', {
        ...data,
        ...this.queryData
      })
      //   console.log(res);
      // 把请求到的数据赋值给certificationlist
      this.certificationlist = res.data.list
      this.total = res.data.total
    },

    // 每页展示的数据条数
    handleSizeChange(val) {
      this.pageSize = val
      this.currentPage = 1
      this.getAllcertification()

      //   console.log(`每页 ${val} 条`);
    },

    // 控制当前页的页数
    handleCurrentChange(val) {
      this.currentPage = val
      this.getAllcertification()
      //   console.log(`当前页: ${val}`);
    },

    // 查询审核信息
    choose() {
        if (!this.Time) {
            var data = {
        // 开始时间时间
        beginTime:'',
        // 结束时间
        endTime: '',
        // 审核状态
        status: this.Certstatus,
        // 申请人编号
        userId: this.userid
      }
        } else {
            var data = {
        // 开始时间时间
        beginTime: Date.parse(this.Time[0]),
        // 结束时间
        endTime: Date.parse(this.Time[1]),
        // 审核状态
        status: this.Certstatus,
        // 申请人编号
        userId: this.userid
      }
        }
      
      // 格式化参数 当某个属性没有值的时候将其删除 以防影响网络请求的操作
      for (const key in data) {
        if (!data[key]) {
          delete data[key]
        }
      }
      this.queryData = data
      this.currentPage = 1
      // 重新刷新数据
      this.getAllcertification()
    },

    // 根据id撤销实名认证
    async handleClick(id) {
      const res = await get('/certification/revokeCertificationApply', { id })
      if (res.status == 200) {
        this.$message({
          message: res.message,
          type: 'success'
        })
      } else {
        this.$message({
          message: res.message,
          type: 'danger'
        })
      }
      // 刷新页面
      this.getAllcertification()
    },

    // 根据id给用户实名认证审核通过
    async checkpass(id) {
      const res = await get('/certification/checkPass', { id })
      if (res.status == 200) {
        this.$message({
          message: res.message,
          type: 'success'
        })
      } else {
        this.$message({
          message: res.message,
          type: 'danger'
        })
      }
      // 刷新页面
      this.getAllcertification()
    },

    // 根据id给用户实名认证审核不通过通过
    async checknopass(id) {
      const res = await get('/certification/checkNoPass', { id })
      if (res.status == 200) {
        this.$message({
          message: res.message,
          type: 'success'
        })
      } else {
        this.$message({
          message: res.message,
          type: 'danger'
        })
      }
      // 刷新页面
      this.getAllcertification()
    }

  }
}
</script>
<style scoped>
/* 分页区域的样式 */
.footer {
  position: fixed;
  bottom: 40px;
  right: 10px;
}
</style>
